<template>
    <div>
        <city-header></city-header>
        <city-search :cities="cities"></city-search>
        <city-list :hotCities="hotCities" :cities="cities" :letter="letter"></city-list>
        <city-alphabet :cities="cities" @change="handleChange"></city-alphabet>
    </div>
</template>
    
<script>
import CityHeader from './components/header'
import CitySearch from './components/search'
import CityList from './components/list'
import CityAlphabet from './components/alphabet'
import axios from 'axios'

export default {
    name: 'City',
    components: {
        CityHeader,
        CitySearch,
        CityList,
        CityAlphabet,
    },
    data(){
        return{
            hotCities: [],
            cities: {},
            letter: ''
        }
    },
    methods: {
        getCityInfo(){
            axios.get('/api/city.json').then((res)=>{
                const msg = res.data
                if(msg.ret && msg.data){
                    const data = msg.data
                    this.hotCities = data.hotCities
                    this.cities = data.cities
                }
            })
        },
        handleChange(letter){
            this.letter = letter
        }
    },
    mounted(){
        this.getCityInfo()
    }
}
</script>

<style lang="stylus" scoped>
    
</style>

